<template>
  <div class="income clearfix">
    <!--    头部区域-->
    <div class="header clearfix">
      <div class="total-money">{{income.toyearincome}}.00</div>
      <img src="./../../../assets/icons/yinliang_bai.svg" alt="" @click="incomeAudioPlay">
      <div class="total-income">2019年总收入 (元)</div>
      <a class="detail" @click="goTo">查看详情</a>
    </div>
    <div class="line"></div>
    <!--    分中心显示区域-->
    <div class="center">
      <h2>分中心</h2>
      <div class="item" v-for="(item, index) in branchList" :key="index" @click="goSubCenter(item)">
        <h3>{{item.branchname}}</h3>
        <div class="left">
          <span class="text">总收入</span>
        </div>
        <div class="right">
          <span class="num red"><i>¥</i>{{item.branchtoyearincome}}.00</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getTotalYearIncome } from './../../../api'
import audioPlay from '../../../utils/audioPlay'
export default {
  name: 'Income',
  data () {
    return {
      // 获取年收入数据
      income: {},
      // 分中心数据
      branchList: []
    }
  },
  mounted () {
    // 获取总收入
    this.getTotalYearIncomeData()
  },
  methods: {
    goTo () {
      this.$router.push('/count/income/detail')
    },
    // 跳转到分中心详情
    goSubCenter (val) {
      console.log(val)
      this.$router.push({
        path: '/count/income/subcenter/detail',
        query: {
          branchcode: val.branchcode,
          branchname: val.branchname
        }
      })
    },
    // 获取年收入数据
    async getTotalYearIncomeData () {
      const res = await getTotalYearIncome()
      // console.log(res)
      this.income = res.data
      this.branchList = res.data.branchList
    },
    incomeAudioPlay () {
      // 定义一个节流阀
      audioPlay(this.income.stringBuilder)
    }
  }
}
</script>

<style scoped lang="less">
  .clearfix:after { /*伪元素是行内元素 正常浏览器清除浮动方法*/
    content: "";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
  }

  .clearfix {
    *zoom: 1; /*ie6清除浮动的方式 *号只有IE6-IE7执行，其他浏览器不执行*/
  }

  .income {
    margin-top: 40px;

    .header {
      overflow: hidden;
      text-align: center;
      img{
        margin-bottom: 10px;
      }

      .total-money {
        font-size: 45px;
        color: #fefefe;
        text-align: center;
        margin-bottom: 8px;
      }

      .total-income {
        font-size: 16px;
        text-align: center;
        color: #fffffd;
      }

      .detail {
        display: block;
        float: right;
        width: 70px;
        height: 24px;
        line-height: 24px;
        border: 1px solid #d2d2d3;
        border-radius: 14px;
        text-align: center;
        color: #fff;
        margin-right: 17px;
        margin-bottom: 15px;
        font-size: 14px;
      }
    }

    .line {
      width: 100%;
      height: 15px;
      background-color: #f5f5f6;
    }

    .center {
      background-color: #fff;
      margin-bottom: 55px;

      h2 {
        font-size: 17.5px;
        color: #2f2f2f;
        font-weight: 600;
        letter-spacing: 1px;
        padding: 15px 0 0 15px;
      }

      .item {
        margin: 0 15px;
        padding: 15px 0;
        height: 100px;
        background-color: #fff;
        border-bottom: 1px solid #e5e5e5;

        &:nth-child(n+2) {
          height: 70px;
        }

        &:last-child {
          border-bottom: 0;
        }

        h3 {
          font-size: 15px;
          color: #5d5d5d;
          margin-bottom: 14px;
        }

        .left {
          float: left;

          .text {
            font-size: 14px;
            color: #989898;
            margin-right: 30px;
          }
        }

        .right {
          float: right;

          .num {
            font-size: 14px;
            color: #f69460;

            i {
              margin-right: 5px;
            }
          }
        }
      }
    }
  }
</style>
